namespace PickGold.Charting
{
    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Globalization;

    internal class AxisIntervalValueConverter : DoubleConverter
    {
        internal bool hideNotSet = true;

        public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
        {
            string strA = value as string;
            if (strA != null)
            {
                if (string.Compare(strA, "Auto", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return 0.0;
                }
                if (string.Compare(strA, "NotSet", StringComparison.OrdinalIgnoreCase) == 0)
                {
                    return (double) 1.0 / (double) 0.0;
                }
            }
            return base.ConvertFrom(context, culture, value);
        }

        public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
        {
            double d = (double) value;
            if (destinationType == typeof(string))
            {
                if (double.IsNaN(d))
                {
                    return "NotSet";
                }
                if (d == 0.0)
                {
                    return "Auto";
                }
            }
            return base.ConvertTo(context, culture, value, destinationType);
        }

        public override TypeConverter.StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            ArrayList values = new ArrayList();
            if (!this.hideNotSet)
            {
                values.Add((double) 1.0 / (double) 0.0);
            }
            values.Add(0.0);
            return new TypeConverter.StandardValuesCollection(values);
        }

        public override bool GetStandardValuesExclusive(ITypeDescriptorContext context)
        {
            return false;
        }

        public override bool GetStandardValuesSupported(ITypeDescriptorContext context)
        {
            return true;
        }
    }
}

